import Button from "@/component/Button";
import { IModalProps, Modal } from "@/component/Modal";
import Show from "@/component/Show";
import { GlobalStore } from "@/store/GlobalStore";
import { VisitorRow } from "./VisitorRow";
import React from "react";

export function LoginModal(props: IModalProps) {
  const [{ sesame, session_id }, dispatch] = GlobalStore.useStore();
  const close_sesame = () => dispatch({ type: 'sesame', payload: false });

  // React.useEffect(() => {
  //   setTimeout(() => dispatch({ type: 'sesame', payload: !0 }), 2000)
  // }, [dispatch])

  return (
    <Modal
      open={sesame}
      onClose={close_sesame}
      title={session_id ? '已登录' : '登录'}
      footer={null}>
      <Show.Switch yes={!!session_id}>
        <Button onClick={() => dispatch({ type: 'logout', payload: null })}>
          登出
        </Button>
        <VisitorRow />
      </Show.Switch>
    </Modal>
  );
}
